package cn.jn.lhm.part01;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

/**
 * 文件拷贝
 *
 * @author lhm 2753914576@qq.com
 * @time 2023/4/5 - 20:23
 **/
public class FilesCopy {
    public static void main(String[] args) throws IOException {
        String source = "D:\\go_code\\goStudy";
        String target = "D:\\go_code\\copy";
        Files.walk(Paths.get(source)).forEach(path -> {
            Path targetPath = Paths.get(path.toString().replace(source, target));
            System.out.println(path);
            if (Files.isDirectory(path)) {
                try {
                    Files.createDirectory(targetPath);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            } else if (Files.isRegularFile(path)) {
                try {
                    Files.copy(path, targetPath);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        });
    }
}
